﻿Imports Microsoft.VisualBasic

Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.IO


Public Class InitPara
    Private m_DataConn As GDataConnection = Nothing
    Private m_UserID As Long = -1
    Private m_UserTypeID As Short = -1
    Private m_UserName As String = "anonimous"
    Private m_ConnString As String = ""
    Private m_passWord As String = ""
    Private m_FullName As String = ""
    Private m_ServerName As String = ""
    Private m_DatabaseName As String = ""

    Public ReadOnly Property GConnection() As GDataConnection
        Get
            Return m_DataConn
        End Get
    End Property

    Public ReadOnly Property DataConnection() As SqlConnection
        Get
            Return m_DataConn.Conn
        End Get
    End Property

    Public Property UserID() As Long
        Get
            Return m_UserID
        End Get
        Set(ByVal value As Long)
            m_UserID = value
        End Set
    End Property

    Public ReadOnly Property ConnectionString() As String
        Get
            Return m_ConnString
        End Get
    End Property

    Public Property UserName() As String
        Get
            Return m_UserName
        End Get
        Set(ByVal value As String)
            m_UserName = value
        End Set
    End Property

    Public Property FullName() As String
        Get
            Return m_FullName
        End Get
        Set(ByVal value As String)
            m_FullName = value
        End Set
    End Property

    Public Property passWord() As String
        Get
            Return m_passWord
        End Get
        Set(ByVal value As String)
            m_passWord = value
        End Set
    End Property

    Public ReadOnly Property ServerName() As String
        Get
            Return m_ServerName
        End Get
    End Property

    Public ReadOnly Property DatabaseName() As String
        Get
            Return m_DatabaseName
        End Get
    End Property

    Public Property UserTypeID() As Short
        Get
            Return m_UserTypeID
        End Get
        Set(ByVal value As Short)
            m_UserTypeID = value
        End Set
    End Property

    Public Sub New()
        m_DataConn = New GDataConnection(Define.ConnStr)
    End Sub

    Public Sub New(ByVal strIniPath As String)
        Try
            m_ConnString = ReadInifile(strIniPath)
            'get databasename & server

            Dim m_ConnArray As String() = New String(4) {}
            m_ConnArray = m_ConnString.Split(";"c)
            m_ServerName = m_ConnArray(0).Split("="c)(1).ToString()
            m_DatabaseName = m_ConnArray(1).Split("="c)(1).ToString()
            '---------------------------------

            m_ConnString += ";Connect Timeout=" + Define.ConnectionTimeOut

            m_DataConn = New GDataConnection(m_ConnString)
        Catch ex As Exception
            Throw (ex)
        End Try
    End Sub

    Public Function ReadInifile(ByVal fileName As String) As String
        Dim strData As String
        Dim fs As FileStream
        Dim intLen As Integer
        Dim byteArr As Byte()
        Dim strArrData As String()

        Try
            ' Read from INI file and decode the data after reading

            fs = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.None)

            intLen = CInt(fs.Length)
            byteArr = New Byte(intLen - 1) {}
            fs.Read(byteArr, 0, intLen)
            fs.Close()
            For i As Integer = 0 To intLen - 1
                byteArr(i) -= 20
            Next
            strData = System.Text.Encoding.ASCII.GetString(byteArr, 0, intLen)
            ' Set up some global variables
            strArrData = strData.Split(New Char() {"|"c})
            Return strArrData(0)
        Catch ex As Exception
            Throw (ex)
        End Try
    End Function

    Public Sub CloseConnection()
        m_DataConn.Close()
    End Sub
End Class
